package net.yxsoft.controller.pc.sysmgt;

import com.jfinal.aop.Clear;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import net.yxsoft.bean.FnFormParams;
import net.yxsoft.controller.pc.sysmgt.common.AuthController;
import net.yxsoft.enumclass.AuditStatusEnumCls;
import net.yxsoft.model.formdesigner.FnFormData;
import net.yxsoft.model.infrastructure.TsUser;
import net.yxsoft.resource.CodeRes;
import net.yxsoft.service.BlockService;
import rapid.core.Authuser;

import java.util.ArrayList;
import java.util.List;

/**
 * @MethodName: BlockController
 * @Description:
 * @param: null
 * @return * @return null
 * @throws
 * @date 2023/8/31 14:49
 * @author jhf
 */
public class BlockController extends AuthController {

  private static BlockService srv = BlockService.me;


  /**
   * @MethodName: browser
   * @Description: 内部链浏览器
   * @param:
   * @return void
   * @throws
   * @date 2023/10/16 14:12
   * @author wj
   */
  public void browser(){




    set("blocks", srv.paginatebyBok_old(null, getParaToInt("p", 1), 10));
    set("kxzh",getPara(0));
    setAttr("zcs",srv.getTrans(getLoginUser(),getPara(0),getPara(1), getParaToInt("p1", 1), 10));
    render("browser.html");
  }





  /**
   * @MethodName: browser
   * @Description:
   * @param:
   * @return void
   * @throws
   * @date 2023/8/31 14:49
   * @author jhf
   */
  @Clear
  public void browserkl(){



      render("lianliulan.html");

  }


  /**
   * @MethodName: getMoreZZView
   * @Description: 获取组织信息
   * @param:
   * @return void
   * @throws
   * @date 2023/10/18 23:17
   * @author wj
   */
  @Clear
  public void getMoreZZView(){

    render("zzList.html");
  }




  /**
  * @MethodName: getJylist_old
  * @Description: 获取存证上链交易折线图信息
  * @param:
  * @return void
  * @throws
  * @date 2023/10/25 13:43
  * @author wj
  */
  @Clear
  public  void getJylist_old(){


    List<Record> gdlist = Db.find("SELECT HOUR(attrib_14) AS HOUR, COUNT(*) AS COUNT\n" +
            "FROM s_blo_trans\n" +
            "WHERE attrib_14 >= NOW() - INTERVAL 24 HOUR  "+
            " GROUP BY HOUR(attrib_14)\n" +
            "ORDER BY HOUR(attrib_14)");
    List list =new ArrayList();
    boolean flag=true;
    //没有数据的天数赋值为0
    for(int i=1;i<25;i++){

      for (int j=0;j<gdlist.size();j++){
        if(i==Integer.parseInt(gdlist.get(j).getStr("HOUR"))){
          list.add(gdlist.get(j).getStr("COUNT"));
          flag=false;
        }
      }
      if(flag){
        list.add("0");
      }
      flag=true;

    }
    renderJson(list);
  }

  /**
   * @MethodName: getJylist
   * @Description: 获取交易折线图信息
   * @param:
   * @return void
   * @throws
   * @date 2023/10/13 13:50
   * @author wj
   */
  public  void getJylist(){

    String val="";
    if(StrKit.notBlank(getPara("selectedValue"))){

      val=getPara("selectedValue");
    }else{
      List list=srv.getqklLsit(getLoginUser());
      if(list!=null && list.size()>0)
        val=srv.getqklLsit(getLoginUser()).get(0).getStr("attrib_01");
    }

    String search=getPara(0);
    String valsql="";
    if(rapid.util.StrKit.notBlank(val)){
      valsql+=" and attrib_02='"+val+"'";
    }
    if(rapid.util.StrKit.notBlank(search)){

      boolean isNumeric = search.matches("-?\\d+(\\.\\d+)?");
      if (isNumeric) {
        valsql+=" and (attrib_01='"+search+"' or attrib_02='"+search+"' or attrib_03='"+search+"' or attrib_04='"+search+"' or attrib_11='"+search+"' or attrib_13='"+search+"'  )";
      }else{
        valsql+=" and (attrib_01='"+search+"' or attrib_02='"+search+"' or attrib_03='"+search+"' or attrib_04='"+search+"'  or attrib_13='"+search+"'  )";
      }

    }

    List<Record> gdlist = Db.find("SELECT HOUR(attrib_14) AS HOUR, COUNT(*) AS COUNT\n" +
            "FROM s_ctransaction\n" +
            "WHERE attrib_14 >= NOW() - INTERVAL 24 HOUR  " +valsql+
            " GROUP BY HOUR(attrib_14)\n" +
            "ORDER BY HOUR(attrib_14)");
    List list =new ArrayList();
    boolean flag=true;
    //没有数据的天数赋值为0
    for(int i=1;i<25;i++){

      for (int j=0;j<gdlist.size();j++){
        if(i==Integer.parseInt(gdlist.get(j).getStr("HOUR"))){
          list.add(gdlist.get(j).getStr("COUNT"));
          flag=false;
        }
      }
      if(flag){
        list.add("0");
      }
      flag=true;

    }
    renderJson(list);
  }

  /**
   * @MethodName: transDetail
   * @Description:
   * @param:
   * @return void
   * @throws
   * @date 2023/8/31 14:49
   * @author jhf
   */
  public void transDetail(){

    String txHash = getPara(0);

    try {
      setAttr("record",srv.getTransDetail(txHash,getLoginUser()));
    }catch (ArrayIndexOutOfBoundsException e){
      setAttr("record",null);
      render("transdetail.html");
    } catch (Exception e) {
      e.printStackTrace();
    }

    render("transdetail.html");
  }
  /**
   * @MethodName: transDetail2
   * @Description:
   * @param:
   * @return void
   * @throws
   * @date 2023/8/31 14:49
   * @author jhf
   */
  @Clear
  public void transDetail2(){

    String txHash = getPara(0);

    try {
      setAttr("record",srv.getTransDetail2(txHash));
    }catch (ArrayIndexOutOfBoundsException e){
      setAttr("record",null);
      render("transdetail2.html");
    }

    render("transdetail2.html");
  }
  /**
   * @MethodName: transDetail3
   * @Description:
   * @param:
   * @return void
   * @throws
   * @date 2023/8/31 14:49
   * @author jhf
   */
  public void transDetail3(){

    String txHash = getPara(0);

    try {
      setAttr("record",srv.getTransDetail3(txHash));
      Record recordlist= Db.findFirst("SELECT * FROM fn_form_data WHERE ATTRIB_07=?",txHash);
      setAttr("recordlist",recordlist);
    }catch (ArrayIndexOutOfBoundsException e){
      setAttr("record",null);
      render("transdetail3.html");
    }

    render("transdetail3.html");
  }
  /**
   * @MethodName: modleBrowser
   * @Description:
   * @param:
   * @return void
   * @throws
   * @date 2023/8/31 14:49
   * @author jhf
   */
  public void modleBrowser(){

    setAttr("trans",srv.getMasterModelTrans("1", ""));
    setAttr("blocks",srv.getBlocks());
    render("switchbrowser.html");

  }
}
